/*
Read CSV file and Extract all the transactions into a list
 */
package Apriori;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

/**
 * @author Yilin/YichaoSun
 */

public class ExtractFile {
    
    public static String csvPath = "tinyset.csv";
    public static ArrayList<HashSet<String>> transactionList = new ArrayList<HashSet<String>>();
    
    private void ReadCSVFile() throws FileNotFoundException, IOException{
        
        BufferedReader input =  new BufferedReader(new FileReader(csvPath));
        
        String tempLine = null;
        while((tempLine = input.readLine())!= null){
            ArrayList<String> tempStrArray = new ArrayList<String>(Arrays.asList(tempLine.split(",")));
            HashSet<String> tempSet = new HashSet<String>();
            Iterator<String> iter = tempStrArray.iterator();
            while(iter.hasNext()){
                String tmpStr = iter.next();
                tempSet.add(tmpStr);
            }
            transactionList.add(tempSet);     
        }
    }
    
    public ExtractFile() throws FileNotFoundException, IOException{
         ReadCSVFile();
    }
 
}
